package com.harvest.scientific.ladder.base

import android.app.Application
import android.content.Context
import com.harvest.scientific.ladder.ext.isDebug
import com.harvest.scientific.ladder.util.AppGlobals
import com.harvest.scientific.ladder.util.LocaleHelper
import com.harvest.scientific.ladder.util.LogUtils
import com.harvest.scientific.ladder.util.SpUtil

class App: Application() {

    override fun attachBaseContext(base: Context) {
        super.attachBaseContext(base)
        sApplication = this
    }

    override fun onCreate() {
        super.onCreate()
        LocaleHelper.setLocale(this, LocaleHelper.getPersistedData(this, "fr"))
        SpUtil.init(this)
        LogUtils.getConfig().apply {
            isLog2FileSwitch = !isDebug()
            setConsoleSwitch(isDebug())
        }
    }


    companion object {
        private var sApplication: Application? = null

        @JvmStatic
        fun getApplication() = if (sApplication == null) AppGlobals.get() else sApplication!!
    }
}